import moment from "moment";

// 对比去重
/**
 * @params
 * @targetArr 目标数组，基准数组
 * @originArr 源数组
 * @key 去重比对键名
 *
 */
export const handleCompareToRepeat = (
  targetArr: any[],
  originArr: any[],
  key: string
) => {
  const noTargetArr: any[] = [];
  const bothArr: any[] = [];
  if (!(!targetArr.length && !originArr.length)) {
    const keyArr: string[] = targetArr.map((targetItem) => targetItem[key]);
    originArr.forEach((originIt: any) => {
      if (!keyArr.includes(originIt[key])) {
        noTargetArr.push({ ...originIt });
      } else {
        bothArr.push({ ...originIt });
      }
    });
  }
  return { noTargetArr, bothArr };
};

// 格式化当前日期所在周几
export const formatDayOfWeek = (date: string | Date) => {
  const today = moment().format("YYYY-MM-DD");
  const yesterday = moment()
    .subtract(1, "days")
    .format("YYYY-MM-DD");
  if (date === today) {
    return "今天";
  } else if (date === yesterday) {
    return "昨天";
  } else {
    const weekOfDay: number = Number(moment(date).format("d"));
    return ["周日", "周一", "周二", "周三", "周四", "周五", "周六"][weekOfDay];
  }
};
